using System;
using System.Collections.Generic;
using System.Text;
using Zoo.View;
using System.Diagnostics;

namespace Zoo.Controller
{
    public partial class LocalizationControlController
    {
        private ILocalizationControlView _viewField;
        private IZooModel _modelField;
        private Dictionary _dictionaryField;

        public LocalizationControlController(ILocalizationControlView view, IZooModel model)
        {
            _viewField = view;
            _modelField = model;
            _dictionaryField = Dictionary.CreateFromCache(_viewField.Language,model);

            //PostCondition
            Debug.Assert(_dictionaryField != null, "Dictionary is Null!");
            Debug.Assert(_modelField != null, "Model is null!");
            Debug.Assert(_viewField != null, "RegisterView is null!"); 
        }



        public void Initialize()
        {
            _viewField.CountrySelectedIndex_Change += new EventHandler(CountrySelectedIndex_Change);

            if (!_viewField.IsPostBack)
            {
                _viewField.CountryValues = _modelField.GetCountryList(_dictionaryField);

                if (_viewField.CountryValues != null && _viewField.CountryValues.Count > 0)
                    _viewField.RegionValues = _modelField.GetRegionList(_viewField.CountryValues[0].Value, _dictionaryField);

            }
            //PostConditions
            Debug.Assert(_viewField.RegionValues != null, "RegisterView RegionValues should not be null!");
            Debug.Assert(_viewField.CountryValues != null, "RegisterView Countryvalues should not be null!");
        }

        public void CountrySelectedIndex_Change(object sender, EventArgs e)
        {
            _viewField.RegionValues = _modelField.GetRegionList(_viewField.CountryID.ToString(), _dictionaryField);
        }
    }
}
